package com.yjdb.sanyuantang.modules.Admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yjdb.sanyuantang.common.result.CommonResult;
import com.yjdb.sanyuantang.modules.Admin.DTO.journal.JournalListDTO;
import com.yjdb.sanyuantang.modules.Admin.DTO.journal.JournalPageDTO;
import com.yjdb.sanyuantang.modules.Admin.DTO.role.RoleListDTO;
import com.yjdb.sanyuantang.modules.Admin.DTO.role.RolePage;
import com.yjdb.sanyuantang.modules.Admin.service.AdminJournalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * packageName com.yjdb.sanyuantang.modules.Admin.controller
 *
 * @author 混沌酱
 * @version 1.0
 * @className AdminJournalController
 * @date 2024/3/18
 * @description TODO
 */
@Tag(name = "后台日志管理")
@RequestMapping("/admin/journal")
@RestController
@SaCheckPermission("sys.journal")
public class AdminJournalController {

    private static final Logger logger = LoggerFactory.getLogger(AdminJournalController.class);

    @Resource
    private AdminJournalService adminJournalService;

    @Operation(summary = "后台日志查询", description = "所提供字段都可以模糊查询,空字符代表全部")
    @RequestMapping(path = "/list", method = RequestMethod.POST)
    public CommonResult<PageInfo<JournalListDTO>> list(@RequestBody JournalPageDTO journalPageDTO) {
        try {
            PageHelper.startPage(journalPageDTO.getPageNum(), journalPageDTO.getPageSize());
            List<JournalListDTO> list = adminJournalService.list(journalPageDTO);
            PageInfo<JournalListDTO> listPage = new PageInfo<>(list);
            return CommonResult.success(listPage);
        } catch (Exception e) {
            logger.debug("查询失败", e);
            return CommonResult.failed(e.getMessage());
        }
    }
}
